from framwork.common.tools  import open_browsers
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

"""写站内信"""
#数据
url=r"http://192.168.1.36/crm/index.php?m=user&a=login"
user_name="admin"
passwd="123456"
nr="大家晚上好！"
#定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_btn_locator=(By.NAME,"submit")
gd_locator=(By.LINK_TEXT,"更多")
znx_locator=(By.LINK_TEXT,"站内信")
xx_locator=(By.CSS_SELECTOR,"#send")
bgs_locator=(By.CSS_SELECTOR,"#dialog-message-send > form > table > tbody > tr:nth-child(1) > td:nth-child(2) > ul > li.active > a")
xzsy_locator=(By.CLASS_NAME,"check_all")
nr_locator=(By.CLASS_NAME,"span5")
save_locator=(By.CLASS_NAME,"btn btn-primary")
#操作
driver=open_browsers()
driver.get(url)
sleep(1)
driver.find_element(*username_locator).send_keys(user_name)
driver.find_element(*password_locator).send_keys(passwd)
driver.find_element(*login_btn_locator).click()
sleep(1)
driver.find_element(*gd_locator).click()
driver.find_element(*znx_locator).click()
driver.find_element(*xx_locator).click()
driver.find_element(*bgs_locator).click()
driver.find_element(*xzsy_locator).click()
driver.find_element(*nr_locator).send_keys(nr)
driver.find_element(*save_locator).click()
sleep(1)
#退出浏览器
sleep(3)
driver.close()